package com.sgzn.sgpay.enums;

import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * 消费优惠规则枚举类
 * @author huangsenguang
 * @version Id: DiscountRuleEnum.java, v 0.1 2018/6/4 18:19 huangsenguang Exp $$
 */
public enum DiscountRuleEnum {
    FIRST_RULE(10, 0),
    SECOND_RULE(20, 0),
    THIRD_RULE(50, 0),
    FOURTH_RULE(100, 0),
    FIFTH_RULE(200, 0),
    SIXTH_RULE(500, 0),
    ;

    @Getter
    private Integer discountLevel;
    @Getter
    private Integer discountAmount;

    //构造函数
    DiscountRuleEnum(Integer discountLevel, Integer discountAmount) {
        this.discountLevel = discountLevel;
        this.discountAmount = discountAmount;
    }

    private static final Map<Integer, Integer> map = new HashMap<>();

    static{
        for(DiscountRuleEnum single : DiscountRuleEnum.values()){
            map.put(single.discountLevel, single.discountAmount);
        }
    }

    /**
     * 根据编码码获取类型
     * @param discountLevel
     * @return
     */
    public static Integer getDescByCode(Integer discountLevel) {
        if(isContain(discountLevel)){
            return map.get(discountLevel);
        }
        return -1;
    }

    public static boolean isContain(Integer discountLevel){
        if(map.containsKey(discountLevel)){
            return true;
        }
        return false;
    }
}

